﻿using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPCAutomatic.DAL
{
    internal class ETableConst
    {
        private readonly string _connectionString;
        public ETableConst(string connectionString)
        {
            _connectionString = connectionString;
        }
        // 获取所有电表常数
        public List<string> GetAllMeterConstants()
        {
            var constants = new List<string>();
            using (var connection = new SQLiteConnection(_connectionString))
            {
                connection.Open();
                const string query = "SELECT [电表常数] FROM [ETableConst] ORDER BY [ID]";

                using (var command = new SQLiteCommand(query, connection))
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        constants.Add(reader["电表常数"].ToString());
                    }
                }
            }
            return constants;
        }
        // 保存用户选择的电表常数索引
        public void SaveSelectedIndex(int index)
        {
            Properties.Settings.Default.SelectedMeterConstantIndex = index;
            Properties.Settings.Default.Save();
        }
        // 获取上次保存的电表常数索引
        public int GetLastSelectedIndex()
        {
            return Properties.Settings.Default.SelectedMeterConstantIndex;
        }
    }
}
